<?php
//if (isset($_SESSION['username'])) {
include_once 'header.php';
require_once("../conn.php");
require_once("../change_page.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" charset= "utf-8 "/>
        <title>乐知家园</title>
        <script language="javascript">
            function change_status(ip,status){
                location.href = "save.action.php?module=changeStatus&ip=" + ip + "&status=" + status;
            }
        </script>
        <style type="text/css">
            <!--
            body,td,th {
                font-family: 微软雅黑;
                font-size: 14px;
                color: #000000;
            }

            .STYLE1 {color: #FFFFFF}
            -->
        </style></head>
    <?php
    /*
      $file = "http://hibaby.sharemysound.com/server/child/serverInterface.php?method=get";
      $json = file_get_contents($file);
      $data = json_decode($json, true);
     */
    $db = new DBC();
    $sql = "SELECT * FROM t_hibaby_server";
    $data = $db->fetchData($sql);
    ?>
    <body>
        <br/>
        <form action="save.action.php?module=server" method="post">
            <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#9999FF">
                <tr align="center">
                    <td align="left">
                        &nbsp;<input type="submit" value="保存" onclick="save()"/></td>
                </tr>
            </table>
            <br/>
            <table width="80%" border="0" align="center" cellpadding="1" cellspacing="1">
                <tr align="center">
                    <td bgcolor="#666666" width="5%"><span class="STYLE1">序号</span></td>
                    <td bgcolor="#666666" width="10%" align="left">&nbsp;&nbsp;<span class="STYLE1">名称</span></td>
                    <td bgcolor="#666666" width="10%" align="left">&nbsp;&nbsp;<span class="STYLE1">服务器IP</span></td>
                    <td bgcolor="#666666" width="5%"><span class="STYLE1">服务器端口号</span></td>
                    <td bgcolor="#666666" width="5%"><span class="STYLE1">最大用户数</span></td>
                    <td bgcolor="#666666" width="10%"><span class="STYLE1">当前用户数</span></td>
                    <td bgcolor="#666666" width="10%"><span class="STYLE1">状态</span></td>
                    <td bgcolor="#666666" width="10%"><span class="STYLE1">操作</span></td>
                </tr>
                <?php
                $num = 0;
                if ($data != false && count($data) > 0) {
                    foreach ($data as $row) {
                        if ($row['status'] == "1") {
                            $status = "<font color='green'>运行</font>";
                        } else {
                            $status = "<font color='red'>暂停</font>";
                        }
                        ?>
                        <tr>
                            <td bgcolor="#FFFFFF">&nbsp;<?php echo++$num; ?></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="name[]" value="<?php echo $row['name']; ?>" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="ip[]" value="<?php echo $row['ip']; ?>" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="port[]" value="<?php echo $row['port']; ?>" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="maxUser[]" value="<?php echo $row['maxUser']; ?>" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<?php echo $row['users']; ?>&nbsp;</td>
                            <td bgcolor="#FFFFFF">&nbsp;<?php echo $status; ?>&nbsp;<input type="hidden" name="status[]" value="<?php echo $row['status']; ?>" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<?php
                if ($row['status'] == "1") {
                    echo "<input type=\"button\" value=\"暂停\" onclick=\"change_status('" . $row['ip'] . "','stop')\" />";
                } else {
                    echo "<input type=\"button\" value=\"使用\" onclick=\"change_status('" . $row['ip'] . "','start')\"  />";
                }
                        ?>&nbsp;</td>
                        </tr>
                        <?php
                    }
                }
                if ($num < 9) {
                    for ($i = $num; $i < 9; $i++) {
                        ?>
                        <tr>
                            <td bgcolor="#FFFFFF">&nbsp;<?php echo++$num; ?></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="name[]" value="" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="ip[]" value="" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="port[]" value="" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;<input type="text" name="maxUser[]" value="" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;&nbsp;<input type="hidden" name="status[]" value="" /></td>
                            <td bgcolor="#FFFFFF">&nbsp;&nbsp;</td>
                            <td bgcolor="#FFFFFF">&nbsp;&nbsp;</td>
                        </tr>
                        <?php
                    }
                }
                ?>
            </table>
        </form>
    </body>
</html>
<?php
include_once '../footer.php';
?>